package com.lianxueda.drawing.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lianxueda.drawing.domain.pojo.Courses;
import com.lianxueda.drawing.domain.pojo.Students;
import com.lianxueda.drawing.domain.vo.ClassStudentVO;
import com.lianxueda.drawing.mapper.ClassCoursesMapper;
import com.lianxueda.drawing.mapper.CoursesMapper;
import com.lianxueda.drawing.mapper.StudentsMapper;
import com.lianxueda.drawing.service.StudentsService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author 28575
* @description 针对表【students】的数据库操作Service实现
* @createDate 2024-08-15 14:40:18
*/
@Service
public class StudentsServiceImpl extends ServiceImpl<StudentsMapper, Students>
    implements StudentsService {
    @Resource
    private StudentsMapper studentsMapper;
    @Resource
    private CoursesMapper coursesMapper;
    @Resource
    private ClassCoursesMapper classCoursesMapper;


    @Override
    public Students findByPhoneNumberAndName(String phone, String studentName) {
        return studentsMapper.findByPhoneNumberAndName(phone, studentName);
    }

    @Override
    public ClassStudentVO getStudentsByClassId(Integer classId) {
        // 从联合表中获取 courseIds 列表
        List<Integer> courseIds = classCoursesMapper.selectCourseIdsByClassId(classId);

        // 根据 courseId 列表获取学生对象列表
        List<Students> students = studentsMapper.selectByCourseIds(courseIds);

        int studentCount = students.size(); // 获取学生总数

        ClassStudentVO classStudentVO = new ClassStudentVO();
        classStudentVO.setCount(studentCount);
        classStudentVO.setStudents(students);

        return classStudentVO;
    }

}




